package com.wisdytech.linkdcs.tool.action;

import com.github.pagehelper.PageInfo;
import com.wisdytech.common.bean.Filter;
import com.wisdytech.common.bean.StandardResult;
import com.wisdytech.common.bean.StandardTableResult;
import com.wisdytech.common.handler.ResourceMatchingService;
import com.wisdytech.common.utils.BaseUtil;
import com.wisdytech.linkdcs.equipment.model.CollectionParam;
import com.wisdytech.linkdcs.equipment.model.Equipment;
import com.wisdytech.linkdcs.equipment.service.IEquipmentRegisteredService;
import com.wisdytech.linkdcs.system.model.SysUser;
import com.wisdytech.linkdcs.tool.model.EqToolConfig;
import com.wisdytech.linkdcs.tool.service.IEqToolConfigService;
import com.wisdytech.linkdcs.tool.vo.ToolConfigVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhanghailin
 * @since 2018-06-05
 */
@Controller
@RequestMapping("/tool/replace")
public class EqToolConfigAction {

    @Resource
    private IEquipmentRegisteredService equipmentRegisteredService;

    @Resource
    private IEqToolConfigService eqToolConfigService;
    @Autowired
    @Qualifier("resourceMatchingService")
    private ResourceMatchingService resourceMatchingService;

    /**
     *
     * <p>Description: 设备信息</p>
     * @param model model
     * @return String
     */
    @RequestMapping("/index")
    public String toolInfoIndex(Model model, HttpServletRequest httpRequest){
        this.resourceMatchingService.getResourceName(httpRequest,model);
        return "tool/toolReplace";
    }

    /**
     * <p>Description:查询设备编号信息列表</p>
     * @return 设备编号信息列表集合
     */
    @RequestMapping(value = "/getEquipList/get.mvc")
    @ResponseBody
    public StandardResult getEquipList(String equipCode){
        List<Equipment> list = eqToolConfigService.getEquipMentByEqCode(equipCode);
        return StandardResult.getSuccessResult(list);
    }

    /**
     * <p>Description:查询设备编号信息列表</p>
     * @return 设备编号信息列表集合
     */
    @RequestMapping(value = "/getToolList/get.mvc")
    @ResponseBody
    public StandardResult getToolList(String equipCode){
        List<ToolConfigVO> list = eqToolConfigService.getToolListByEquipCode(equipCode);
        return StandardResult.getSuccessResult(list);
    }

    /**
     * 分页查询接口
     * @param equipCode 必须穿 设备编码
     * @param filter 分页参数
     * @return 分页结果
     */
    @RequestMapping(value = "/getToolConfigByFilter/get.mvc")
    @ResponseBody
    public StandardTableResult<EqToolConfig> getToolListByFilter(String equipCode, Filter filter) {
        PageInfo<EqToolConfig> page = this.eqToolConfigService.getEqToolListByFilter(equipCode,filter);
        return new StandardTableResult<>(page.getTotal(),page.getList());
    }

    /**
     * 保存/更新工装配置信息
     * @param eqToolConfig 实体类
     * @return StandardResult
     */
    @RequestMapping(value = "/saveEqToolConfig/save.mvc")
    @ResponseBody
    public StandardResult saveEqToolConfig(EqToolConfig eqToolConfig) {
        SysUser user = BaseUtil.getCurrentUser();
        this.eqToolConfigService.saveEqToolConfig(eqToolConfig,user);
        return StandardResult.getSuccessResult();
    }

    /**
     * 更新工装配置信息
     * @param eqToolConfig 实体类
     * @return StandardResult
     */
    @RequestMapping(value = "/replaceTool/save.mvc")
    @ResponseBody
    public StandardResult replaceTool(EqToolConfig eqToolConfig) {
        SysUser user = BaseUtil.getCurrentUser();
        this.eqToolConfigService.replaceTool(eqToolConfig,user);
        return StandardResult.getSuccessResult();
    }

    
    /**
     * 模糊查询新增的更换信息分页查询接口
     * @param equipCode 必须穿 设备编码
     * @param toolCode 工装编码
     * @param filter 分页参数
     * @return 分页结果
     */
    @RequestMapping(value = "/getToolConfigByToolCode/get.mvc")
    @ResponseBody
    public StandardResult getToolConfigByToolCode(String equipCode, Filter filter,String toolCode) {
        List<EqToolConfig> list = this.eqToolConfigService.getToolConfigByToolCode(equipCode,filter,toolCode);
        return StandardResult.getSuccessResult(list);
    }
    
    /**
     * <p>Description:模糊查询设备工装编号信息列表</p>
     * @return 设备编号信息列表集合
     */
    @RequestMapping(value = "/getToolListBytoolCode/get.mvc")
    @ResponseBody
    public StandardResult getToolListBytoolCode(String equipCode,String toolCode){
        List<ToolConfigVO> list = eqToolConfigService.getToolListBytoolCode(equipCode,toolCode);
        return StandardResult.getSuccessResult(list);
    }


    /**
     *
     * @param equipCode 设备编码
     * @param search 参数 名称查询参数
     * @return 该设备关联的采集参数集合
     */
    @RequestMapping(value = "/findCollectionParamByEquipCode/get.mvc")
    @ResponseBody
    public StandardResult findCollectionParamByEquipCode(String equipCode, String search) {
        List<CollectionParam> list = this.eqToolConfigService.findCollectionParamByEquipCode(equipCode,search);
        return StandardResult.getSuccessResult(list);
    }

    /**
     * <p>Description:模糊查询设备工装编号信息列表</p>
     * @return 设备编号信息列表集合
     */
    @RequestMapping(value = "/getoToolBytoolCode/get.mvc")
    @ResponseBody
    public StandardResult getoToolBytoolCode(String equipCode,String toolCode){
        EqToolConfig eqToolConfig = eqToolConfigService.getoToolBytoolCode(equipCode,toolCode);
        return StandardResult.getSuccessResult(eqToolConfig);
    }


}
